import * as echarts from "echarts";
import {get} from "@/api/requests";

export async function fetchWeightHis(params) {
    return get('hcmw/fetchWeightHis', params);
}
export async function drawHisLine(myLineChart, res) {
    let lineChart = echarts.init(myLineChart);
    let series_data = res['series_data'];
    let series_Y = res['series_yAxis'];
    let option = {
        tooltip:{},
        title: {
            text: "历史记录数据",
            subtext: "体重过往趋势图",
            left: 'center',
            padding: [10, 10, 10, 10],
        },
        xAxis: {
            type: 'category',
            data: series_Y
        },
        yAxis: {
            type: 'value',
            min: 50,
            max: 100,
            scale:true,
            nameLocation: 'end',
            minInterval: 3,
            axisLine: {
                show: true,
                symbol:['none',"none"],
                symbolSize: [10,15],
                lineStyle:{
                    color: "#333333",
                    width: '1',
                    type: "solid"
                },
            },
            axisLabel : {
                show: true,
                interval: '0',
                color: "#333333",
                fontsize: 13,
                showMinLabel: true,
                showMaxLabel: true
            },
            splitLine: {
                show: true,
                type: 'dashed'
            }
        },
        series: [{
            type: "line",
            data: series_data,
            smooth: true,
            label: {
                normal: {
                    "fontSize": 15,
                    "show":true,
                    "position": "top"
                }
            }
        }]
    };
    lineChart.clear();
    lineChart.setOption(option, true);
    window.addEventListener("resize", () => {
        lineChart.resize();
    })
    return lineChart;
}